﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsmShaderConverter
{
    class LoadFxFile
    {
        enum typeOfLine
        {
            PixelShader,
            VertexShader,
            None
        }
        public static void LoadFromFile(string filename, out string linesPixelShader, out string lineVertexShader)
        {
            StringBuilder psLines = new StringBuilder();
            StringBuilder vsLines = new StringBuilder();

            using (StreamReader sr = new StreamReader(filename))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    line = line.Trim();

                    if (line.StartsWith("PixelShader "))
                        while ((line = sr.ReadLine()) != null)
                        {
                            line = line.Trim();

                            if (line.StartsWith("}"))
                                break;

                            psLines.AppendLine(line);
                        }

                    if (line.StartsWith("VertexShader "))
                        while ((line = sr.ReadLine()) != null)
                        {
                            line = line.Trim();

                            if (line.StartsWith("}"))
                                break;

                            vsLines.AppendLine(line);
                        }

                    if (line.StartsWith("technique "))
                        while ((line = sr.ReadLine()) != null)
                        {
                            line = line.Trim();

                            if (line.StartsWith("}"))
                                break;
                        }
                }
            }

            linesPixelShader = psLines.ToString();
            lineVertexShader = vsLines.ToString();
        }
    }
}
